import request from '@/utils/request'

//查询全部MPN
export function getMPNlist(pageNum, pageSize) {
  return request({
    url: '/ctManage/getMPNlist',
    method: 'get',
    params: {  // GET请求使用params
      pageNum: pageNum,  // 动态接收pageNum
      pageSize: pageSize // 动态接收pageSize
    }
  })
}

//查询全部产线列表
export function getAllLine() {
  return request({
    url: '/ctManage/getLineList',
    method: 'get'
  })
}

//查询获取对应部门的全部人员
export function getUserIdUserNameByDeptId() {
  return request({
    url: '/ctManage/getUserIdUserNameByDeptId',
    method: 'get',
    params: {  // GET请求使用params
      deptId: 205,  // 传入编号205的部门
    }
  })
}

//查询获取对应人员全部的
export function getUserLinkLine(userId) {
  return request({
    url: '/ctManage/getUserLinkLine',
    method: 'get',
    params: {  // GET请求使用params
      userId: userId,  // 传入对应的userID
    }
  })
}

export function setUserLinkLine(userId, lineId) {
  return request({
    url: '/ctManage/setUserLinkLine',
    method: 'post',
    data: {
      lineId: lineId, // 传入对应的lineId
      userId: userId  // 传入对应的userID
    }
  })
}

// 删除ct
export function delct(Id) {
  return request({
    url: '/ctManage/del/'+Id,
    method: 'delete'
  })
}

//添加品目
export function addMPN(data) {
  return request({
    url: '/ctManage/addMPN',
    method: 'post',
    data: data
  })
}

//通过登录的账户获取链接的产线
export function getUserLinkLineByLogin() {
  return request({
    url: '/ctManage/getUserLinkLineByLogin',
    method: 'get'
  })
}

//获取查询的CT表
export function getCTTableByLineIdEnterDateMPNName(pageNum, pageSize, mpnName,ie, line, timeStar, timeEnd) {
  return request({
    url: '/ctManage/getCTTableByLineIdEnterDateMPNName',
    method: 'post',
    data: {
      pageNum: pageNum,
      pageSize: pageSize,
      mpnName: mpnName,
      ie:ie,
      line: line,  // Ensure this is an array
      timeStar: timeStar,
      timeEnd: timeEnd
    }
  })
}

//获取查询的CT表
export function getCTTableByCTId(ct_id) {
  return request({
    url: '/ctManage/getCTTableByCTId',
    method: 'get',
    params: { 
      ct_id: ct_id,  
    }
  })
}

//获取查询的CT表
export function getCTTableByLineIdEnterDateMPNNameHaveData(pageNum, pageSize, mpnName,ie, line, timeStar, timeEnd) {
  return request({
    url: '/ctManage/getCTTableByLineIdEnterDateMPNNameHaveData',
    method: 'post',
    data: {
      pageNum: pageNum,
      pageSize: pageSize,
      mpnName: mpnName,
      ie:ie,
      line: line,  // Ensure this is an array
      timeStar: timeStar,
      timeEnd: timeEnd
    }
  })
}



//获取查询的CTdb表
export function getCTTableDBByLineIdEnterDateMPNName(params) {
  return request({
    url: '/ctManage/getCTTableDBByLineIdEnterDateMPNName',
    method: 'post',
    data:params
  })
}

//条件查询MPN表
export function selectMPNByQueryParams(pageNum, pageSize, mpnName,ie, line_id, state, timeStar, timeEnd) {
  return request({
    url: '/ctManage/selectMPNByQueryParams',
    method: 'get',
    params: {  // GET请求使用params
      pageNum: pageNum,
      pageSize: pageSize,
      mpnName: mpnName,
      ie:ie,
      line_id: line_id,
      state: state,
      timeStar: timeStar,
      timeEnd: timeEnd
    }
  })
}

//导入MPN模板
export function exportTemplate() {
  return request({
    url: '/ctManage/template',
    method: 'get',
    responseType: 'blob'  // 关键：必须指定响应类型为blob
  })
}

//导入MPN数据
export function importExcel(data) {
  return request({
    url: '/ctManage/excel',
    method: 'post',
    data: data,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

//修改状态
export function setMpnState(id, state) {
  return request({
    url: `/ctManage/setMpnState`,
    method: 'put',
    params: {
      id: id,
      state: state
    }
  })
}

//添加品目
export function setCTtable(data) {
  return request({
    url: '/ctManage/setCTtable',
    method: 'post',
    data: data
  })
}

//导出ct表
export function ctExport() {
  return request({
    url: '/ctManage/exportCT',
    method: 'post',
    responseType: 'blob',
  })
}

//导出mpn表
export function mpnExport() {
  return request({
    url: '/ctManage/exportMpn',
    method: 'post',
    responseType: 'blob',
  })
}

//导入CT模板
export function exportctTemplate() {
  return request({
    url: '/ctManage/cttemplate',
    method: 'get',
    responseType: 'blob'  // 关键：必须指定响应类型为blob
  })
}

//导入CT数据
export function importctExcel(data) {
  return request({
    url: '/ctManage/ctexcel',
    method: 'post',
    data: data,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

//批量设置状态
export function setBatchMpnState(multipleSelection) {
  return request({
    url: '/ctManage/setBatchMpnState',
    method: 'put',
    data: multipleSelection
  })
}